package com.itheima.fanshe2;

import java.lang.reflect.Field;

/*
获取类的 成员变量的信息
 */
public class Demo04 {

    public static void main(String[] args) throws NoSuchFieldException {

        Class<Student> clazz = Student.class;

        //getFields   属性对象数组  获取所有公有的 属性
        Field[] fields = clazz.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }
        System.out.println("=====");
        //getDeclaredFields  获取所有的属性 包含私有
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }
        System.out.println("===========");

        //getField

        Field address = clazz.getField("address");
        System.out.println(address);
        Field score = clazz.getField("score");

        System.out.println(score);
        //getDeclaredField
        Field name = clazz.getDeclaredField("name");
        System.out.println(name);
        Field age = clazz.getDeclaredField("age");
        System.out.println(age);

    }
}
